package com.application.tourapp;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.application.tourapp.R;
import com.application.tourapp.httppost.FeedBackHttpPost;
import com.application.tourapp.model.FeedBack;

public class SettingsActivity extends GenericActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		Button   mButton;
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings_activity);
		setHeader(getResources().getString(R.string.Settings), true, true);
//		ArrayList<String> differentCities = getCities();
		
		Spinner spinner = (Spinner) findViewById(R.id.spinner1);
		// Create an ArrayAdapter using the string array and a default spinner layout
		List<String> list = new ArrayList<String>();
		list.add("Nantes");
		list.add("Paris");
		list.add("Nice");
		list.add("Toulouse");
		ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
			android.R.layout.simple_spinner_item, list);
		dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(dataAdapter);
		
		
		mButton = (Button)findViewById(R.id.button3);
	    final EditText mEdit = (EditText)findViewById(R.id.editText1);

	    mButton.setOnClickListener(
	        new View.OnClickListener()
	        {
	            @Override
				public void onClick(View view)
	            {
					//Log.v("EditText", mEdit.getText().toString());
	            	FeedBack feedBack = new FeedBack();
	            	feedBack.setMessage(mEdit.getText().toString());
	            	if(!feedBack.getMessage().trim().equals("")) {
		            	if(new FeedBackHttpPost().postFeedback(feedBack)) {
		            		Toast.makeText(getApplicationContext(), getResources().getString(R.string.Sent), Toast.LENGTH_SHORT).show();
		            		mEdit.setText("");
		            	} else {
		            		Toast.makeText(getApplicationContext(), getResources().getString(R.string.NotSent), Toast.LENGTH_SHORT).show();
		            		mEdit.setText("");
		            	}
	            	} else {
	            		Toast.makeText(getApplicationContext(), getResources().getString(R.string.Data), Toast.LENGTH_SHORT).show();
	            	}
	            	
	            }
	        });
        
	}
}
